import { addLogs } from './services/api/log';

export const postionEnum = {
  1: '设计师',
  2: '销售',
  3: '其他',
};

export type commonType = {
  id: number;
  name: string;
  nickname: string;
};

export const fnAddLog = async (actionRef: any, router: any) => {
  const userInfo = JSON.parse(localStorage.getItem('userInfo') || '');

  const obj = {
    user_by_id: userInfo.id,
    user_by: userInfo.nickname,
    type: 'export',
    operate: router.pathName,
    operate_name: router.name + '表',
  };
  const res = await addLogs(obj);
  if (res) {
    actionRef.current?.reload();
  }
};

export const initMoney = (
  money: number,
  local?: string,
  params?: { style: 'currency'; currency: 'CNY' | string },
) => {
  const localStr = local || 'zh-CN';
  const data = params || {
    style: 'currency',
    currency: 'CNY',
  };
  const formatMoney = new Intl.NumberFormat(localStr, data);
  return formatMoney.format(money || 0);
};
